<template>
  <div>
    <el-form ref="myform" :model="formItem" label-width="100px" size="mini" class="form-view">
      <el-row :gutter="40">
        <el-col :span="12">
          <el-form-item label="审批意见">
            {{ formItem.opinionName }}
          </el-form-item>
        </el-col>
      </el-row>
      <el-row v-if="formItem.opinion !=='pass'" :gutter="40">
        <el-col :span="24">
          <el-form-item label="未通过原因">
            {{ formItem.reason }}
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
  </div>
</template>

<script>
import { detail } from '@neu/dcom-ui/api/changeApproval'
const formItem = {
  opinion: '',
  reason: '',
  opinionName: ''
}
export default {
  name: 'ChangeApprovalView',
  components: {},
  props: {
    taskId: {
      required: false,
      type: String,
      default: 'NULL'
    },
    workOrderNum: {
      required: false,
      type: String,
      default: ''
    }

  },
  data() {
    return {
      // 列表
      opinionData: [{ key: 'pass', label: '通过' }, { key: 'notpass', label: '不通过' }, { key: 'disallowance', label: '驳回' }],
      formItem: {
        ...formItem
      }
    }
  },
  watch: {
  },
  created() {
    this.fetch()
  },
  methods: {
    fetch() {
      if (this.workOrderNum !== 'NULL') {
        detail(this.workOrderNum, this.taskId).then(response => {
          this.formItem = {
            ...response.data
          }
          const opinionFilter = this.opinionData.filter(s => s.key === this.formItem.opinion)
          if (opinionFilter.length > 0) {
            this.formItem.opinionName = opinionFilter[0].label
          }
        })
      } else {
        this.formItem = {
          ...formItem
        }
      }
    },
    reset() {
      this.$refs.myform.resetFields()
      this.formItem = { ...formItem }
    }
  }
}
</script>
